import axios from "axios";

export const AJAX_START = 'AJAX_START'
export const AJAX_SUCCESS = 'AJAX_SUCCESS'
export const AJAX_ERROR = 'AJAX_ERROR'

//  失败与成功的状态
// 101 未登录
const successStatus = 1000;
const errorStatus = [900,101];


axios.interceptors.response.use(function (res) {

    if(res.status == 200){
        if (res.data.code === successStatus) {
            return  Promise.resolve(res.data)
        } else if(errorStatus.indexOf(res.data.code) !== -1){
            console.log(errorStatus.indexOf(res.data.code))
            return  Promise.reject(res.data)
        }else {
            return Promise.reject(res.data)
        }
    }
}, function (ex) {

    return  Promise.reject(ex.data)
});


export default axios;